define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'trades/assets/myaccount/index' + location.search,
                    // add_url: 'trades/assets/myaccount/add',
                    // edit_url: 'trades/assets/myaccount/edit',
                    // del_url: 'trades/assets/myaccount/del',
                    // multi_url: 'trades/assets/myaccount/multi',
                    // import_url: 'trades/assets/myaccount/import',
                    table: 'activity_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                       // {checkbox: true},
                        {field: 'orderid', title: __('Orderid'), operate: 'LIKE'},
                        //{field: 'account_id', title: __('Account_id')},
                        {field: 'amount', title: __('Amount'),operate:false},
                        {
                            field: 'state',
                            title: __('State'),
                            visible:false,
                            searchList: {"2":'已支付',"4":'已退款'}
                        },
                        {
                            field: 'state_text',
                            title: __('State'),
                            operate:false,
                            formatter:function(value,row) {
                                if (row['state'] == 1) {
                                    return '<span style="color:black">' + value + '</span>';
                                } else if (row['state'] == 2) {
                                    return '<span style="color:yellowgreen">' + value + '</span>';
                                } else if (row['state'] == 3) {
                                    return '<span style="color:red">' + value + '</span>';
                                } else if (row['state'] == 4) {
                                    return '<span style="color:red">' + value + '</span>';
                                }
                            }
                        },
                       // {field: 'activity_id', title: __('Activity_id')},
                        {field: 'createTime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'name', title: __('name'), align: 'left', operate: 'LIKE %...%', placeholder: '活动名称搜索'},
                      //  {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});